// PURPOSE: Import a subset of variables from datasets in the data_final folder
// and save as dta files.

clear all

// SET MACROS
global Input  "O:/data_final"
global Output "Y:/limited/Michigan_CTE/funding_change/data_derived/imported"

// IMPORT DATA

// K-12 student
local vars ric year grade_fnl bcode_weight female white black hisp povertyflag ///
  speddummy lep frac_attend hybrid_exitstatus_final censusblockgroup1

use `vars' using $Input/epi_student/k12_student.dta
save $Output/k12_student.dta, replace

// Math & reading score
local vars ric grade year mathstdss mathvalid readingstdss readingvalid elastdss elavalid

use `vars' if year >= 2005 & grade == 8 using $Input/epi_assessment/assessment_student_year_level.dta
save $Output/math_reading_score.dta, replace

// ACT & SAT score
local vars ric grade year actcompositestd actenglishstd actreadingstd actmathstd ///
  satcompositestd satreadingwritingstd satmathstd

use `vars' if year >= 2007 & grade == 11 using $Input/epi_assessment/assessment_student_year_level.dta
save $Output/act_sat_score.dta, replace

// Postsecondary enrollment (from NSC)
local vars ric year public_fall public_spring public_summer private_fall private_spring ///
  private_summer four_yr_fall four_yr_spring four_yr_summer two_yr_fall two_yr_spring ///
  two_yr_summer

use `vars' using $Input/epi_postsec/nsc_clean_student_x_year_level.dta
save $Output/nsc_enrollment.dta, replace

// School-level data
local vars bcode year schoolname_cleaned dcode dname isdcode entitytype urbanicity school_type d_urbanicity ///
  highgrade level charter enroll per_frl fte_experience   

use `vars' if year >= 2007 & !missing(year) using $Input/epi_infrastructure/school_level.dta
save $Output/school_level.dta, replace

// Census block
local vars year fips2010 edu_ba edu_pro edu_ms

use `vars' if year >= 2007 & !missing(year) using $Input/epi_census/MI2010blckgrpcontrols.dta
save $Output/census_block.dta, replace
